package com.uhaou.system.action;

/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2010
 */ 

import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.commons.lang.xwork.StringUtils; 

import cn.org.rapid_framework.page.Page;
import cn.org.rapid_framework.web.scope.Flash;

import com.uhaou.common.base.BaseStruts2Action;
import com.uhaou.common.util.EasyUIJsonUtil;
import com.uhaou.common.util.Json; 
import com.uhaou.system.model.*; 
import com.uhaou.system.service.*; 
import com.uhaou.system.vo.query.*; 

import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

/**
 * @author   
 * @version 1.0
 * @since 1.0
 */

public class SysDictAction extends BaseStruts2Action implements Preparable,
		ModelDriven {
 	protected static final String DEFAULT_SORT_COLUMNS = null;

	// forward paths
	protected static final String QUERY_JSP = "/admin/sysDict/query.jsp";
	protected static final String LIST_JSP = "/admin/sysDict/list.jsp";
	protected static final String CREATE_JSP = "/admin/sysDict/create.jsp";
	protected static final String EDIT_JSP = "/admin/sysDict/edit.jsp";
	protected static final String SHOW_JSP = "/admin/sysDict/show.jsp"; 

	// redirect paths,startWith: !
	protected static final String LIST_ACTION = "!/admin/sysDict/list.jsp";

	private ISysDictManager sysDictManager;

	private SysDict sysDict;
	java.lang.String id = null;
	private String ids;

	private ISysUserManager sysUserManager;

	public void setSysUserManager(ISysUserManager sysUserManager) {
		this.sysUserManager = sysUserManager;
	}
    public String userName; 

    
	public String password;

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}

	public void setParam(String param) {
		this.param = param;
	}

	private String param;

	public void prepare() throws Exception {
		if (isNullOrEmptyString(id)) {
			sysDict = new SysDict();
		} else {
			sysDict = (SysDict) sysDictManager.getById(id);
		}
	}

	/** 澧炲姞setXXXX()鏂规硶,spring灏卞彲浠ラ�氳繃autowire鑷姩璁剧疆瀵硅薄灞炴��,娉ㄦ剰澶у皬鍐� */
	public void setSysDictManager(ISysDictManager manager) {
		this.sysDictManager = manager;
	}

	public Object getModel() {
		return sysDict;
	}

	public void setFuncId(java.lang.String val) {
		this.id = val;
	}
 
	public String list() {
		if (StringUtils.isNotBlank(param)) {
			SysDictQuery query = newQuery(SysDictQuery.class,
					DEFAULT_SORT_COLUMNS);

			/*Page page = sysDictManager.findPage(query);
			savePage(page,query);
			Map map = new HashMap();
			map.put("total", page.getTotalCount());
			map.put("rows", page.getResult());
			return writeAjaxResponse(Json.toJson(map));*/
		} else{
			 
		}
			return LIST_JSP;
	}

	/** 鏌ョ湅瀵硅薄 */
	public String show() {

		return SHOW_JSP;
	}

	 
	  
	public String create() {
		String parentId = getText("parentId");
		 
			SysDictQuery query = newQuery(SysDictQuery.class,
					DEFAULT_SORT_COLUMNS);
			// 璁剧疆涓�涓緢澶х殑pagesize
			query.setPageSize(10000); 
			List<SysDict> list = sysDictManager.find(query);
			 
			 
		 
			return CREATE_JSP;

	} 
	public String save() {
		try {
			sysDictManager.save(sysDict);
			Flash.current().success(CREATED_SUCCESS); // 瀛樻斁鍦‵lash涓殑鏁版嵁,鍦ㄤ笅涓�娆ttp璇锋眰涓粛鐒跺彲浠ヨ鍙栨暟鎹�,error()鐢ㄤ簬鏄剧ず閿欒娑堟伅

			return writeAjaxResponse("1");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
 
	public String edit() {
		return EDIT_JSP;
	}
 
	public String update() {
		sysDictManager.update(this.sysDict);
		Flash.current().success(UPDATE_SUCCESS);
		try {
			getResponse().getWriter().write("1");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return LIST_ACTION;
		// return LIST_ACTION;
	}
 
	public String delete() {
		String[] idsArray = ids.split(",");
		for (String id : idsArray) {
			sysDictManager.deleteById(id);
		}
		Flash.current().success(DELETE_SUCCESS);
		return LIST_ACTION;
	}
	
 

}

